// Charge l'ensemble des radars

function requestCovoiturage() {
  var sqlQ = "SELECT ID,LONGITUDE,LATITUDE,DESCRIPTION FROM 2619484";
  var sql = encodeURIComponent(sqlQ);
  var query = new google.visualization.Query('http://www.google.com/fusiontables/gvizdata?tq=' + sql);
  query.send(loadCovoiturage);
}

function loadCovoiturage(response) {
  // Load all radars
  var rows = response.getDataTable(); 
  for (var i=0; i<rows.getNumberOfRows(); i++) {
     createCovoiturageMarker('covoiturage', rows, i);
  }
}

function createCovoiturageMarker(layerName, rows, index) {
  var layer = layers[layerName];
  var id = rows.getValue(index,0);
  var lng = rows.getValue(index,1);
  var lat = rows.getValue(index,2);
  var desc = rows.getValue(index,3);
  var point= new google.maps.LatLng(lat, lng); 
  
  var model = new Object();
  model['lat'] = lat;
  model['lng'] = lng;
  model['desc'] = desc;
  
  var myMarkerOpts = {
    position: point,
    icon: "./images/carpool.gif"
  };
  
  var marker = new google.maps.Marker(myMarkerOpts);
  var infoWindow = new google.maps.InfoWindow();
  
  infoWindow.setContent(desc);
  google.maps.event.addListener(marker, 'click', function() {  
    if (openedInfoWindow != null) { 
      openedInfoWindow.close();
    }
    infoWindow.open(map, marker); 
    openedInfoWindow  = infoWindow;
  });              
  
  var markerDef = new Object();
  markerDef['id'] = id;
  markerDef['marker'] = marker;
  markerDef['infoWindow'] = infoWindow;
  markerDef['model'] = model;
  layer['markers'].push(markerDef);
  
}



